--守缺三分
local shouquesanfen = fk.CreateSkill {
    name = "mcdh_shouquesanfen"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

shouquesanfen:addEffect(fk.GameStart,{
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(shouquesanfen.name)
    end,
    on_cost=function() return true end,
    on_use=function (self, event, target, player, data)
        local room = player.room
        lib.askForPublicCard(room,player,player,3,3,shouquesanfen.name,false,"#shouquesanfen-public",'.',false)
    end
})

shouquesanfen:addEffect(fk.EventPhaseStart,{
    can_trigger=function (self, event, target, player, data)
        return target == player and data.phase == Player.Play and player:hasSkill(shouquesanfen.name)
    end,
    on_cost=function (self, event, target, player, data)
        local room = player.room
        local n = #lib.getPublicCards(player)
        if n ~= 0 then
            event:setCostData(self,n)
            return room:askToSkillInvoke(player,{skill_name=shouquesanfen.name,prompt="#shouquesanfen-draw:::"..n})
        end
    end,
    on_use=function (self, event, target, player, data)
        local n =  event:getCostData(self)
        player:drawCards(n,shouquesanfen.name)
    end
})

shouquesanfen:addEffect(fk.EventPhaseEnd,{
can_trigger=function (self, event, target, player, data)
    local room = player.room
    if target == player and data.phase == Player.Play and player:hasSkill(shouquesanfen.name) then
        local n = 0
        room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
            if e.data.from == player then
            n = n + 1
            end
            return false
        end, Player.HistoryPhase)
        return n <= #lib.getPublicCards(player) 
    end
    end,
    on_cost=function (self, event, target, player, data)
        return true
    end,
    on_use=function (self, event, target, player, data)
        local room = player.room 
        if player:isWounded() then
            room:recover({who = player,skillName=shouquesanfen.name,num = 1})
        end
        room:setPlayerMark(player,"#shouquesanfen",1)
    end
})


shouquesanfen:addEffect("maxcards",{
    fixed_func=function (self, player)
        if player:getMark("#shouquesanfen") ~= 0 then
            return 4
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_shouquesanfen"] = "守缺三分",
    [":mcdh_shouquesanfen"] = "游戏开始时，你明置三张牌。出牌阶段开始时，你可以摸X张牌。出牌阶段结束后，若你本阶段使用牌数不大于X，你回复1点体力，本回合手牌上限为4。（X为你的明置牌数）",
    ["#race-qingxuxishou-choose"] = "守缺三分: 摸 %arg 张牌。",
    ["#shouquesanfen-publice"] = "守缺三分:明置三张牌"
}

return shouquesanfen